<!-- 修改密码表单 -->
<form class="layui-form model-form">
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">用户名:</label>
        <div class="layui-input-block">
            <input type="text" name="user" placeholder="请输入用户名" class="layui-input" lay-verType="tips">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">旧密码:</label>
        <div class="layui-input-block">
            <input type="text" name="oldpwd" placeholder="请输入旧密码" class="layui-input" lay-verType="tips" lay-verify="psw">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">新密码:</label>
        <div class="layui-input-block">
            <input type="text" name="newpwd" placeholder="请输入新密码" class="layui-input" lay-verType="tips" lay-verify="psw">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">确认密码:</label>
        <div class="layui-input-block">
            <input type="text" name="rePsw" placeholder="请再次输入新密码" class="layui-input" lay-verType="tips" lay-verify="equalTo" lay-equalTo="input[name=newpwd]">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block text-right">
            <button class="layui-btn" lay-filter="submit-psw" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </div>
</form>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'admin', 'formX'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;

        // 监听提交
        form.on('submit(submit-psw)', function (data) {
            admin.closeDialog('[lay-filter="submit-psw"]');
            $.ajax({
                type: "POST",
                url: "ajax.php?act=pwd",
                data: data.field,
                dataType: "json",
                success: function(data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
					        icon: 6,
					        time: 2000,
					        end: function() {
						        window.location.href = "login.php"
					        }
				        });
                    } else {
                        layer.msg(data.msg, { icon: 5 });
                    }
                }
            });
            return false;
        });
        
    });
</script>